package com.iot.core.mybatisflex;

import com.mybatisflex.core.dialect.IDialect;
import com.mybatisflex.core.exception.FlexAssert;
import com.mybatisflex.core.logicdelete.LogicDeleteProcessor;
import com.mybatisflex.core.logicdelete.impl.BooleanLogicDeleteProcessor;
import com.mybatisflex.core.logicdelete.impl.DefaultLogicDeleteProcessor;
import com.mybatisflex.core.logicdelete.impl.IntegerLogicDeleteProcessor;
import com.mybatisflex.core.logicdelete.impl.PrimaryKeyLogicDeleteProcessor;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.table.IdInfo;
import com.mybatisflex.core.table.TableInfo;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;

import static com.mybatisflex.core.constant.SqlOperator.EQUALS;



public class MyLogicDeleteProcessor extends IntegerLogicDeleteProcessor {

@Override
public String buildLogicNormalCondition(String logicColumn, TableInfo tableInfo, IDialect dialect) {
    String sql = dialect.wrap(logicColumn) + EQUALS +   getLogicDeletedValue() ;
    if(Arrays.stream(tableInfo.getAllColumns()).anyMatch(x->x.toLowerCase().equals("edt_dt".toLowerCase()))){
        sql+=",edt_dt=now()";
    }
    if(Arrays.stream(tableInfo.getAllColumns()).anyMatch(x->x.toLowerCase().equals("edt_uid".toLowerCase()))){
        sql+=",edt_uid=1000";
    }

    return sql;

}

}
